/*CoreUtil*/
/*工具类，类似java静态工具类*/
var CoreUtil = (function() {
	var coreUtil = {};
	var header = {};
	/*ajax请求*/
	coreUtil.ajax = function(url, params, success, method) {
		var roleSaveLoading = top.layer.msg('请稍后 ...', {
			icon : 16,
			time : false
		});
		layui.$.ajax({
			url : url,
			type : typeof method == 'undefined' ? "POST" : method,
			data : params,
			dataType : "json",
			//headers : CoreUtil.header(),
			success : function(res) {
				top.layer.close(roleSaveLoading);
				if (res.code == 0 || res.code==1) {
					success(res);
				} else {
					layer.msg("系统出错！请稍后试试或联系管理员！");
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				top.layer.close(roleSaveLoading);
				if (XMLHttpRequest.status == 404) {
					top.window.location.href = "/404";
				} else {
					layer.msg("服务器好像出了点问题！请稍后试试！");
				}
			}
		});
	};
	coreUtil.header = function() {
		var tokenName = CoreUtil.getData("tokenName")
		var tokenValue = CoreUtil.getData("tokenValue")
		if (typeof tokenName == 'undefined' || typeof tokenValue == 'undefined') {
			layer.alert('登录TOKEN不存在，请重新登录！', {
				icon : 0,
				shadeClose : true,
			//title: 'icon: '+ icon
			},
				function() {
					window.location.href = '/index.html';
				}
			);
		}
		header[tokenName] = tokenValue;
		return header
	};
	return coreUtil;
})(CoreUtil, window);